
#if !defined (_JSON_STR_H)
#define _JSON_STR_H

#include <stdlib.h>

namespace json
{

	class str
	{

	public:

		str(void);
		str(const char *);
		str(const str &);
		~str(void);

		operator char*(void);
		operator const char*(void);
		
		str & operator =(const char *);
		str & operator =(const str &);

		str & operator +=(char);
		str & operator +=(const char *);
		str & operator +=(const str &);

		str & operator +(const char *);
		str & operator +(const str &);

		bool equals(const str &);
		void substr(unsigned int = 0, unsigned int = 0);
		void trim(char = ' ');

		inline int allocated(void) { return _allocated; }

	private:
		
		inline void _null_end(void) { _data[_size] = '\0'; }
		inline int _c_str_len(const char * a) const { int i = 0; while (a[i++] != '\0'); return i; }
		inline void _str_cpy(char * src, char * dest, int count) { for (int i = 0; i < count; ++i) dest[i] = src[i]; }
		inline void _mem_assert(unsigned int req) 
		{ 
			if (_allocated < req) 
			{
				_data = (char*)realloc(_data, req + 4);
				_allocated = req;
			}
		}

		unsigned int _allocated;
		unsigned int _size;
		char * _data;
	};

}

#endif
